<template>
	<view class="play">
		<view class="list">
			
		</view>
		<AudioPlay :list="audioList" :albumName="albumName" @callPlay="callPlay"></AudioPlay>
	</view>
</template>

<script>
	import AudioPlay from "@/components/audio-play.vue"
	export default{
		components: {AudioPlay},
		data(){
			return {
				audioList: [],
				albumName: '',
				playing: false
			}
		},
		onLoad() {
			// 到本页关闭悬浮窗
			if(getApp().globalData.sphere){
				getApp().globalData.sphere.hide()
			}
			
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.on('init', data => {
			    console.log(data)
				this.audioList = data.list.map(item => {
					return {
						title: item.name,
						src: item.file,
						cover: item.cover
					}
				})
				this.albumName = data.name
			})
		},
		onUnload() {
			// 开启悬浮窗
			if(getApp().globalData.sphere && this.playing){
				getApp().globalData.sphere.show()
			}
		},
		methods: {
			callPlay(playing){
				this.playing = playing
			}
		}
	}
</script>

<style scoped>
	.play{
		display: flex;
		flex-direction: column;
		height: 100vh;
	}
	.list{
		flex: 1;
	}
</style>